package com.loren.demo23.license;

import oshi.SystemInfo;
import oshi.hardware.ComputerSystem;
import oshi.hardware.HardwareAbstractionLayer;

public class ServerInfo {

    /**
     * linux:
     * 1、dmidecode -t system, UUID - 转大写
     * 2、cat /sys/class/dmi/id/product_uuid
     * windows：
     * 1、wmic csproduct get UUID
     */
    private final String hardwareUUID;

    private static volatile ServerInfo serverInfo;

    private ServerInfo() {
        SystemInfo systemInfo = new SystemInfo();
        HardwareAbstractionLayer hardware = systemInfo.getHardware();
        ComputerSystem computerSystem = hardware.getComputerSystem();
        this.hardwareUUID = computerSystem.getHardwareUUID();
    }

    public static ServerInfo getInstance() {
        if (serverInfo == null) {
            synchronized (ServerInfo.class) {
                if (serverInfo == null) {
                    serverInfo = new ServerInfo();
                }
            }
        }
        return serverInfo;
    }

    public String getHardwareUUID() {
        return hardwareUUID;
    }
}
